using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using JigLibX.Physics;
using Microsoft.Xna.Framework.Input;
using sqengine.Components;
using sqengine.Engine.Common;

namespace sqengine
{
    public class MapInfoDrawer : DrawableGameComponent
    {

        SpriteBatch spriteBatch;

        SpriteFont spriteFont,spriteFont2;
        
        string _mapinfo;

        AdvancedContent _adcontent;
        Game _game;

        int bbWidth, bbHeight;

        public MapInfoDrawer(Game game, AdvancedContent adcontent, string mapinfo)
            : base(game)
        {
            this._adcontent = adcontent;
            this._mapinfo = mapinfo;
            this._game = game;
            LoadContent();

        }

        private void GraphicsDevice_DeviceReset(object sender, EventArgs e)
        {
            bbWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
            bbHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
        }

        protected override void LoadContent()
        {
            this._game.GraphicsDevice.DeviceReset += new EventHandler(GraphicsDevice_DeviceReset);

            spriteBatch = new SpriteBatch(_game.GraphicsDevice);
            spriteFont = _adcontent.LoadSpriteFont("Fonts\\Miramo");
            spriteFont2 = _adcontent.LoadSpriteFont("Fonts\\Verdana");

            base.LoadContent();
        }

        protected override void UnloadContent()
        {
            base.UnloadContent();
        }


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            if (spriteBatch != null)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(spriteFont, _mapinfo, new Vector2(_game.GraphicsDevice.Viewport.Width / 2 - spriteFont.MeasureString(_mapinfo).X / 2, 10), Color.Red);
                spriteBatch.End();
            }

            ((sqengine)this.Game).RestoreRenderState();
            

        }
    }
}
